package browser;

/* 
 * Author: rendy.jr
 * Date: Jun 10, 2011
 * 6.005 Elements of Software Construction
 * Rendy Bambang Junior
 * rendy.jr@gmail.com
 * 
 * VectorCache is an implementation of cache in Vector
 * It contains vector of Page
 * VectorCache reponsible for :
 * - put page if url doesn't exist
 * - get page if url exist
 * 
 */

import java.util.Vector;

public class VectorCache implements Cache{
	Vector<Page> pages;
	
	public VectorCache(){
		pages = new Vector<Page>();
	}
	
	public Page get(String urlString){
		for(Page p : pages){
			if(p.getURL().toString().equals(urlString))
				return p;
		}
		return null;
	}
	
	public void put(Page page){
		for(Page p : pages){
			if(p.getURL().toString().equals(page.getURL().toString())){
				p.content = page.content;
				return;
			}
		}
		pages.add(page);
	}
}
